/*
 * p1155.cpp
 *
 *  Created on: 2013-7-24
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 3005;
struct node
{
	int v, len;
} tmp;
vector<node> son[maxn];
int dp[maxn][maxn], num[maxn], value[maxn];
int n, m;
void dfs(int u)
{
	dp[u][0] = 0;
	for (int i = 0; i < son[u].size(); i++)
	{
		dfs(son[u][i].v);
		num[u] += num[son[u][i].v];
	}
	if (son[u].size() == 0)
	{
		num[u] = 1;
		dp[u][1] = value[u];
	}
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i].v;
		int len = son[u][i].len;
		for (int j = num[u]; j >= 1; j--)
			for (int k = 1; k <= num[v] && k <= j; k++)
				dp[u][j] = max(dp[u][j], dp[u][j - k] + dp[v][k] - len);

	}
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n - m; i++)
	{
		int k, a, b;
		scanf("%d", &k);
		for (int j = 1; j <= k; j++)
		{
			scanf("%d%d", &a, &b);
			tmp.v = a;
			tmp.len = b;
			son[i].push_back(tmp);
		}
	}
	for (int i = n - m + 1; i <= n; i++)
		scanf("%d", &value[i]);
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			dp[i][j] = -INF;
	dfs(1);
	for (int i = n; i >= 0; i--)
		if (dp[1][i] >= 0)
		{
			printf("%d\n", i);
			break;
		}
	return 0;
}
